#!/user/bin/env python3
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# @File : demo_01.py
# @Time : 2022-05-31 17:23
# @Author : mojin
# @Email : 397135766@qq.com
# @Software : PyCharm
#-------------------------------------------------------------------------------

# 导入webdriver
from appium import webdriver
import time
import subprocess,re,time,os,signal

#from selenium.webdriver.common.by import By
from appium.webdriver.common.mobileby import MobileBy
# 初始化参数
# desired_caps = {
#     'platformName': 'Android',  # 被测手机是安卓
#     'platformVersion': '7',  # 手机安卓版本
#     'deviceName': '3dd69892',  # 设备名，adb devices获取
#     'appPackage': "com.gsx.tiku",  # 启动APP Package名称com.qdmetro.xahl.ar.eye  com.hyh.suianyun.app
#     'appActivity':"com.gsx.tiku.activity.CoverActivity",  #aapt dump badging  xx.apk
#     'unicodeKeyboard': True,  # 使用自带输入法，输入中文时填True
#     'resetKeyboard': True,  # 执行完程序恢复原来输入法
#     'noReset': True,  # 不要重置App，如果为False的话，执行完脚本后，app的数据会清空，比如你原本登录了，执行完脚本后就退出登录了
#     'newCommandTimeout': 500,
#     'automationName': 'UiAutomator2'
# }
# 连接Appium Server，初始化自动化环境

desired_caps ={'platformName': 'Android',
               'newCommonTimeout': 500,
               'noReset': True,
               'deviceName': 'emulator-5554',
               'platform_version': '7.1.2',
               'app': 'D:\\Python\\python3\\gongchengfenxian\\pytest-appium-allure-demo\\app\\base.apk',
               'appPackage': "com.gsx.tiku",
               'appActivity': "com.gsx.tiku.activity.CoverActivity",
               'udid': 'emulator-5554',
               'systemPort': 8200}


#http://127.0.0.1:4723/wd/hub
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# 设置等待时间，如果不给时间的话可能会找不到元素
driver.implicitly_wait(20)

tv_agree = (MobileBy.ID, "com.gsx.tiku:id/tv_agree")  # 同意使用并开始
tv_login_pwd = (MobileBy.ID, "com.gsx.tiku:id/tv_login_pwd")  # 切换为密码登录
LoginID = (MobileBy.ID, 'com.gsx.tiku:id/et_phone')  # 输账号框
LoginPWD = (MobileBy.ID, 'com.gsx.tiku:id/et_pwd')  # 输入密码框
iv_select = (MobileBy.ID, "com.gsx.tiku:id/iv_select")  # 勾选用户协议
bt_login = (MobileBy.ID, "com.gsx.tiku:id/bt_login")  # 登录按钮
tvName = (MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("我的")')
tvNickName = (MobileBy.ID, "com.gsx.tiku:id/tvNickName")  # 账户id

#command='adb -s 3dd69892 shell screenrecord  --time-limit 180 /sdcard/test_swipe.mp4'
driver.find_element(*tv_login_pwd).click()# 切换为密码登录
driver.find_element(*LoginID).send_keys('18192750673')# 输账号框
driver.find_element(*LoginPWD).send_keys('mojin123456')# 输入密码框
driver.find_element(*iv_select).click()# 勾选用户协议
time.sleep(2)
#driver.find_element(*bt_login).click() # 登录按钮

time.sleep(10)

#os.kill(process.pid, signal.CTRL_C_EVENT)
# 退出程序，记得之前没敲这段报了一个错误 Error: socket hang up 啥啥啥的忘记了，有兴趣可以try one try
driver.quit()

